package com.jzg.template.refreshrecycleview;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by jzg on 2015/12/22.
 */
public abstract class RecycleViewBaseAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    public  OnItemClickLitener mOnItemClickLitener;
    public  OnItemLongClickLitener mOnItemLongClickLitener;

    @Override
    public abstract RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType);

    @Override
    public  void onBindViewHolder(final RecyclerView.ViewHolder holder, int position){
        if(mOnItemClickLitener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });
        }
        if(mOnItemLongClickLitener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemLongClickLitener.onItemLongClick(holder.itemView, pos);
                }
            });
        }
    };

    @Override
    public abstract int getItemCount() ;


    public interface OnItemClickLitener
    {
        void onItemClick(View view, int position);
    }
    public interface OnItemLongClickLitener
    {
        void onItemLongClick(View view, int position);
    }
    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    public void setOnItemLongClickLitener(OnItemLongClickLitener mOnItemLongClickLitener)
    {
        this.mOnItemLongClickLitener = mOnItemLongClickLitener;
    }

}
